package com.itheima.utils;


import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


/**
 * Servlet工具类
 */
public class ServletUtils {

    /**
     * 获取request
     */
    public static HttpServletRequest getRequest()
    {
        return getRequestAttributes().getRequest();
    }


    /**
     * 获取ServletRequestAttributes
     * @return
     */
    public static ServletRequestAttributes getRequestAttributes()
    {
        //获取当前线程的requestAttributes
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        return (ServletRequestAttributes) attributes;
    }
}
